/*
 * @Author: soso
 * @Date: 2022-02-17 18:08:52
 * @LastEditTime: 2022-03-10 11:11:29
 * @LastEditors: Please set LastEditors
 * @Description: 自动探测活跃节点
 * @FilePath: /gomeshsync/core/cfiles/ping.go
 */
package cfiles

import (
	"context"
	"gomeshsync/config"
	"gomeshsync/pingpong"
	"math"
	"time"
)

// 探测活跃节点
func Pingpong(ctx context.Context) {
	c := config.GetConfig()

	for {
		select {
		case <-ctx.Done():
			return
		default:
			pingpong.NewPingpong(config.PathOfNodes).Ping(c.DataPort)
		}

		// 最小60秒
		ai := int(math.Max(60, float64(c.AnInterval)))
		time.Sleep(time.Second * time.Duration(ai))
	}
}
